var app = getApp(); //获取应用实例
const quote = app.globalData.quote;
const mta = quote.mta;
const api = quote.api;
const path = quote.paths

Page({
    data: {
        path: path,
        transactionList: [],
        hideloadmore: true,
        pageindex: 0,
    },
    onLoad: function(options) {
        // 生命周期函数--监听页面加载
        var that = this;

        that.GetUserAccountDetails();
    },
    onReady: function() {
        // 生命周期函数--监听页面初次渲染完成
    },
    onShow: function() {
        // 生命周期函数--监听页面显示
    },
    onHide: function() {
        // 生命周期函数--监听页面隐藏
    },
    onUnload: function() {
        // 生命周期函数--监听页面卸载
    },
    // 页面相关事件处理函数--监听用户下拉动作
    onPullDownRefresh: function(params) {
        var that = this;

        //数据加载完后停止刷新
        setTimeout(() => {
            console.log('停止刷新');
            wx.stopPullDownRefresh();
        }, 1000);

    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
        var that = this;

        console.log('tobottom');
        if (!that.data.hideloadmore) {

            return
        }
        wx.showLoading({
            title: '加载中',
        })

        that.setData({
            pageindex: that.data.pageindex + 1
        })

        that.GetUserAccountDetails(that.data.pageindex, function(res) {
            wx.hideLoading();
            if (that.data.transactionList.length == res.data.data.Record) {
                that.setData({
                    hideloadmore: false
                })
            }
        })

    },
    GetUserAccountDetails: function(params, cb) {
        var that = this;

        var dataDic = {
            OpenId: app.globalData.openId,
            pagesize: 30,
            pageindex: params || 0,
        }
        api.methodGetUserAccountDetails({
            dataDic: dataDic,
            complete: function(res) {
                console.log('用户账户提现', res);
                if (res.data.code != 0) {
                    wx.showModal({
                        title: '温馨提示',
                        content: res.data.msg,
                        showCancel: false,
                        success: function(res) {
                            if (res.confirm) {
                                console.log('用户点击确定')
                            }
                        }
                    })
                    return
                }
                //将新数据合并到原数据中
                var transactionList = that.data.transactionList;
                transactionList = transactionList.concat(res.data.data.DetailList);
                that.setData({
                    transactionList: transactionList,
                })
                typeof cb == 'function' && cb(res);
            }
        })
    },
    onShareAppMessage: function() {
        // 用户点击右上角分享
        return {
            title: 'title', // 分享标题
            desc: 'desc', // 分享描述
            path: 'path' // 分享路径
        }
    }
})